package service;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.Build;
import android.os.IBinder;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import android.widget.RemoteViews;

import com.example.administrator.sdscanner.MainActivity;
import com.example.administrator.sdscanner.R;

public class MyService extends Service {
    public MyService() {
    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO: Return the communication channel to the service.
        throw new UnsupportedOperationException("Not yet implemented");
    }

    @Override
    public void onDestroy() {
        Log.d("MyService", "onDestroy executed!!!!");
        super.onDestroy();
    }

    @Override
    public void onCreate() {
        Log.d("MyService", "onCreate executed!!!!");
        super.onCreate();
//        Notification mNotification = new Notification();//为了兼容问题，不用该方法，所以都采用BUILD方式建立
//		Notification mNotification  = new Notification.Builder(this).getNotification();//这种方式已经过时
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
//		//PendingIntent 跳转动作
        PendingIntent pendingIntent=PendingIntent.getActivity(this, 0, new Intent(), 0);
        NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        mBuilder.setSmallIcon(R.drawable.music1)
                .setTicker("常驻通知来了")
                .setContentTitle("常驻测试")
                .setContentText("使用cancel()方法才可以把我去掉哦")
                .setContentIntent(pendingIntent);
        Notification mNotification = mBuilder.build();
        //设置通知  消息  图标
        mNotification.icon = R.drawable.music1;
        //在通知栏上点击此通知后自动清除此通知
//        mNotification.flags = Notification.FLAG_AUTO_CANCEL;//FLAG_ONGOING_EVENT 在顶部常驻，可以调用下面的清除方法去除  FLAG_AUTO_CANCEL  点击和清理可以去调
        //设置显示通知时的默认的发声、震动、Light效果
//        mNotification.defaults = Notification.DEFAULT_VIBRATE;
        //设置发出消息的内容
        mNotification.tickerText = "通知来了";
        //设置发出通知的时间
        mNotification.when=System.currentTimeMillis();
		mNotification.flags = Notification.FLAG_AUTO_CANCEL; //在通知栏上点击此通知后自动清除此通知
//		mNotification.setLatestEventInfo(this, "常驻测试", "使用cancel()方法才可以把我去掉哦", null); //设置详细的信息  ,这个方法现在已经不用了
        mNotificationManager.notify(100, mNotification);

//        NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
//        builder.setContentTitle("BigPictureStyle");
//        builder.setContentText("BigPicture演示示例");
//        builder.setSmallIcon(R.drawable.guitar);
//        builder.setDefaults(NotificationCompat.DEFAULT_ALL);
////        builder.setLargeIcon(BitmapFactory.decodeResource(getResources(),R.drawable.back));
////        android.support.v4.app.NotificationCompat.BigPictureStyle style = new android.support.v4.app.NotificationCompat.BigPictureStyle();
////        style.setBigContentTitle("BigContentTitle");
////        style.setSummaryText("SummaryText");
////        style.bigPicture(BitmapFactory.decodeResource(getResources(),R.drawable.back));
////        builder.setStyle(style);
//        builder.setAutoCancel(true);
//        manager.notify(1, builder.build());
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.d("MyService", "onStartCommand executed!!!!");
        return super.onStartCommand(intent, flags, startId);
    }
}
